package com.atguigu.gmall.search.vo;

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.Date;
import java.util.List;
// javabean和 es的索引库以及映射关联：注解
@Document(indexName = "goods" , replicas = 2 , shards = 2)
@Data
public class Goods {
    //创建多表联合的复杂javabean时，主表数据属性 一般直接写，如果其他表的属性一般会使用表名作为前缀
    @Id
    private Long skuId;
    @Field(type = FieldType.Keyword)
    private String defaultImage;
    @Field(type = FieldType.Text ,analyzer = "ik_max_word")
    private String title;
    @Field(type = FieldType.Double)
    private Double price;
    @Field(type = FieldType.Keyword)
    private String subtitle;
    @Field(type = FieldType.Boolean)
    private Boolean store = false;//默认无货
    @Field(type = FieldType.Long)
    private Long sales = 0L;//销量
    @Field(type = FieldType.Date , format = DateFormat.date)
    private Date createTime;//创建时间
    //品牌
    @Field(type = FieldType.Long)
    private Long brandId;
    @Field(type = FieldType.Keyword)
    private String brandName;
    @Field(type = FieldType.Keyword)
    private String logo;
    //分类
    @Field(type = FieldType.Long)
    private Long categoryId;
    @Field(type = FieldType.Keyword)
    private String categoryName;
    /*
        FieldType.Object: 会导致es数据出现扁平化问题
        > 查询searchAttrValues attrId=1 attrValue为8G   attrId=2 attrValue=256G

        {
            skuId: [1]
            searchAttrValues.attrId:[1,2]
            searchAttrValues.attrValue:[8G,128G]
        }
        {
            skuId:1,
            searchAttrValues:[
                {
                    attrId:1
                    attrName: 运存,
                    attrValue:8G
                },
                {
                    attrId:2
                    attrName: 存储,
                    attrValue:128G
                }

            ]
        },
        {
            skuId:2
            searchAttrValues:[
                {
                    attrId:1
                    attrName: 运存,
                    attrValue:6G
                },
                {
                    attrId:2
                    attrName: 存储,
                    attrValue:256G
                }

            ]
        }





     */
    //spu和sku检索属性集合:Nested避免数据扁平化   (就是将集合中的对象每一个单独创建一个子文档来存储)
    //如果是Object： 采用级联属性 和值的集合方式来存储，同一个级联属性的多个值会存到一个集合列表中'
    @Field(type = FieldType.Nested) //以后查询嵌套属性时需要指定nested查询
    List<SearchAttrValue> searchAttrValues;
}
